// pages/verification/verification.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: false,
    select1: false,
    select2: false,
    verifyDatetime: '核销时间',
    // buyType: '所有状态',
    verify: '所有状态',
    thaw: '手机号码',
    cancelType: ['所有状态','落位核销','认购核销'],
    cancel: ['所有状态', '核销成功', '核销失败'],
    type:['手机号码','签约人','订单编号'],
    opition: false,
    sellMoneyCount: '',//出售金额初始值
    verifySuccessCount:'',//核销次数初始值
    detailsList:[],
    inputValue:'',//input初始值
    // 时间选择器
    currentDate: new Date().getTime(),
    minDate: '',
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    }
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '核销记录',
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //渲染数据
    this.checked()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 下拉框选项
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  // 选择日期
  onInput(event) {
    this.setData({
      currentDate: event.detail
    });
  },
  //时间选择器确定按钮
  closePicker(e){
    console.log(app.dateFormats(e.detail))
    var data=app.dateFormats(e.detail)
   
    this.setData({
      verifyDatetime: data,
      select: false,
      time:e.detail
    });
  },
  //时间选择器取消按钮
  closePickers(){
    this.setData({
      verifyDatetime:'核销时间',
      select: false
    });
  },
  // 第二个下拉框选项
  // bindShowMsg1() {
  //   this.setData({
  //     select1: !this.data.select1
  //   })
  // },
  // mySelect1(e) {
  //   var name = e.currentTarget.dataset.name
  //   this.setData({
  //     buyType: name,
  //     select1: false
  //   })
  // },
  // 第三个下拉框选项
  bindShowMsg2() {
    this.setData({
      select2: !this.data.select2
    })
  },
  mySelect2(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      verify: name,
      select2: false
    })
  },
  // 搜索下拉框
  bindShowThaw() {
    this.setData({
      opition: !this.data.opition
    })
  },
  myOpition(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      thaw: name,
      opition: false
    })
  },

  // 输入框
  bindKeyInput(e){
    this.setData({
      inputValue: e.detail.value
    })
  },

  //搜索
  checked(){
    var buyTypes='';
    if (this.data.buyType=='所有状态'){
      buyTypes=''
    } else if (this.data.buyType == '落位核销'){
      buyTypes=1
    }else{
      buyTypes = 2
    }
    var verifys='';
    if (this.data.verify == '所有状态') {
      verifys = ''
    } else if (this.data.verify == '核销成功') {
      verifys = 1
    } else {
      verifys = 0
    }
    var time = '';
    if (this.data.verifyDatetime!='核销时间'){
      time = this.data.time
    }else{
      time=''
    }
    wx.request({
      url: app.url + '/order/auth3/orderForm/findVerifyById',
      method: 'GET',
      header: {
        token: wx.getStorageSync('token'),
      },
      data: {
        projectId: wx.getStorageSync('id'),
        // buyType: buyTypes,
        verify: verifys,
        verifyDatetime:time,
        orderNo: this.data.thaw == '订单编号' ? this.data.inputValue : '',
        contractName: this.data.thaw == '签约人' ? this.data.inputValue : '',
        contractMobile: this.data.thaw == '手机号码' ? this.data.inputValue : ''
      },
      success: (res) => {
        if (res.data.code == 0) {
          if (res.data.data.length != 0) {
            this.setData({
              verifySuccessCount: res.data.data[0].verifySuccessCount,
                sellMoneyCount: res.data.data[0].sellMoneyCount.toFixed(2),
            })
            // 时间戳转换时间日期
            var detailsList = res.data.data
            for (var i = 0; i < res.data.data.length; i++) {
              detailsList[i].submitTime = app.dateFormat(res.data.data[i].verifyDatetime)
              detailsList[i].downPayTime = app.dateFormat(res.data.data[i].downPayTime)
            }
            this.setData({
              detailsList: detailsList
            })
          }else{
            this.setData({
              detailsList: [],
              verifySuccessCount: '',
              sellMoneyCount: ''
            })
          }
        }else{
          wx.showModal({
            title: '提示',
            showCancel: false,
            content: res.data.msg
          });
        }
      }
    })
  }
})